home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
edit
/
pt20pc.zip
/
SETUP.C
< prev
next >
Wrap
C/C++ Source or Header
|
1991-02-04
|
23KB
|
1,005 lines
#include "pt.h"
#include "malloc.h"
#include "string.h"
#include "stdlib.h"
#include "conio.h"
#include "io.h"
static unsigned char *buffer, *fileBuffer;
static int bufLeft = 0, bufferSize;
static int lineNumber;
void pascal
setGWBuffer( allocate )
int allocate;
{
if( allocate ) {
bufferSize = 4096;
while( 1 ) {
fileBuffer = malloc(bufferSize);
if( fileBuffer != NULL )
break;
bufferSize /= 2;
}
} else
free(fileBuffer);
}
int pascal
/* XTAG:setup */
setup()
{
extern unsigned char msgBuffer[];
extern unsigned char textBuffer[];
extern struct optionItem options[];
extern int debug;
extern union REGS rin, rout;
extern unsigned char textColor, selColor;
extern unsigned char bannerColor, borderColor, elevColor;
extern unsigned char topColor;
extern unsigned char windowPoints[];
extern struct colorCycle colorCycles[];
extern unsigned char maxTextCycles;
extern unsigned char maxBorderCycles;
int i, j, fid;
register unsigned char *p;
register unsigned char *item;
int triedLocalIni;
setGWBuffer(1); /* allocate buffer space */
triedLocalIni = 0;
p = findFile("pt.ini");
if( p == NULL )
return 1;
fid = openls(p, 0);
processLocalIni:
lineNumber = 1;
bufLeft = 0;
buffer = fileBuffer;
while( 1 ) {
item = getWord(fid);
if( item == NULL )
break;
if( *item == '\0' )
continue;
p = strchr(item, '=');
if( p == NULL ) {
if( *item != '[' ) {
cprintf(
"Missing '=' in pt%s.ini (line %d) item: \"%s\"\r\n",
(triedLocalIni ? "local" : ""),
lineNumber,
item);
goto contError;
}
} else
*p++ = '\0';
if( *item == '[' ) {
setMenu(item, fid);
continue;
}
for(i = 0; options[i].index != OLASTITEM; i++) {
for(j = 0; options[i].name[j] != '\0'; j++) {
if( tolower(options[i].name[j])
!= tolower(item[j]) )
goto iContinue;
}
/*************unixMode kludge -- temporary ***************/
if( strncmp(item, "unix", 4) == 0 ) options[i].type = OINTEGER;
goto foundIt;
iContinue:
;
}
/* compute some things to check for invalid fields */
j = isdigit(*(item+1)); /* second char is a digit */
i = *(item+3) == '\0'; /* length is three */
/* key definition? */
if( tolower(*item) == 'k' && j ) {
setKey(item, p);
continue;
}
/* button definition? */
if( tolower(*item) == 'b' && i ) {
setButton(item, p);
continue;
}
#ifdef OVERLAYS
/* overlay command definition? */
if( tolower(*item) == 'c' && j ) {
setOverlay(item, p);
continue;
}
#endif
/* mouse motion 1 definition? */
if( tolower(*item) == 'm' && j ) {
setMMotion(1, item, p);
continue;
}
/* mouse motion 2 definition? */
if( tolower(*item) == 'n' && j ) {
setMMotion(2, item, p);
continue;
}
/* mouse motion quadrant definition? */
if( tolower(*item) == 'q' && j ) {
setMQuadrant(item, p);
continue;
}
/* top line menu definition? */
if( tolower(*item) == 't' && i ) {
setTopline(item, p, 0);
continue;
}
/* bottom line menu definition? */
if( tolower(*item) == 'l' && i ) {
setTopline(item, p, 1);
continue;
}
/* window mouse point definition? */
if( tolower(*item) == 'w' && (*(item+4)=='\0') ) {
setWindowPoint(item, p);
continue;
}
/* else we don't know what it is */
cprintf("Unknown option name [%s] in pt%s.ini (line %d)\r\n",
item, (triedLocalIni ? "local" : ""), lineNumber);
contError:
cprintf("Press any key to continue\r\n");
incon();
continue;
foundIt:
setOption(i, p, NULL);
}
closels(fid);
/* see if there is a ptlocal.ini */
if( !triedLocalIni ) {
triedLocalIni = 1;
fid = openls("ptlocal.ini", 0);
if( fid >= 0 )
goto processLocalIni;
}
/* set the first color cycle to the default colors */
colorCycles[0].textColor = textColor;
colorCycles[0].selColor = selColor;
colorCycles[0].bannerColor = bannerColor;
colorCycles[0].borderColor = borderColor;
colorCycles[0].elevColor = elevColor;
/* set the default color modes */
if( maxTextCycles == 0 ) {
maxTextCycles = 1;
colorCycles[1].textColor = textColor;
colorCycles[1].selColor = selColor;
}
if( maxBorderCycles == 0 ) {
maxBorderCycles = 1;
colorCycles[1].bannerColor = bannerColor;
colorCycles[1].borderColor = borderColor;
colorCycles[1].elevColor = elevColor;
}
setGWBuffer(0); /* free buffer space */
bufLeft = 0;
return 0;
}
void pascal
/* XTAG:setTopline */
setTopline(s, value, onBottom)
unsigned char *s, *value;
int onBottom;
{
extern unsigned char toplineVector[];
extern int menuLine;
extern int firstTopMenu;
int shifts, buttons, commandNumber, i;
if( (onBottom && menuLine > 0)
|| (!onBottom && menuLine < 0) ) {
cprintf("Mixing top and bottom menus in pt.ini\r\n");
cprintf("Press any key to continue\r\n");
incon();
onBottom = !onBottom;
}
commandNumber = atoi(value);
if( commandNumber == -1 )
commandNumber = FDONOTHING;
sscanf(&s[1], "%1x", &shifts);
sscanf(&s[2], "%1x", &buttons);
/* fix shifts so that either shift keys implies shift */
/* shift over bit1 and OR bit0 with it */
shifts = (shifts>>1) | (shifts&0x1);
i = ((shifts&0x7)<<3) + (buttons&0x7);
toplineVector[i] = (unsigned char)commandNumber;
if( onBottom )
--menuLine;
else
++menuLine;
}
void pascal
/* XTAG:setButton */
setButton(s, value)
unsigned char *s, *value;
{
extern unsigned char buttonVector[];
int shifts, buttons, commandNumber, i;
commandNumber = atoi(value);
if( commandNumber == -1 )
commandNumber = FDONOTHING;
sscanf(&s[1], "%1x", &shifts);
sscanf(&s[2], "%1x", &buttons);
i = ((shifts&0x7)<<3) + (buttons&0x7);
buttonVector[i] = (unsigned char)commandNumber;
}
void pascal
/* XTAG:setMMotion */
setMMotion(which, s, value)
int which;
unsigned char *s, *value;
{
extern int mouseVec1[];
extern int mouseVec2[];
int commandNumber, i;
commandNumber = atoi(value);
if( commandNumber == -1 )
commandNumber = FDONOTHING;
i = *++s - '0';
if( i < 0 || i > 8 )
return;
if( which == 1 )
mouseVec1[i] = commandNumber;
else
mouseVec2[i] = commandNumber;
}
void pascal
/* XTAG:setWindowPoint */
setWindowPoint(s, value)
register unsigned char *s;
unsigned char *value;
{
extern unsigned char msgBuffer[];
extern unsigned char windowPoints[];
int commandNumber, n;
commandNumber = atoi(value);
if( commandNumber == -1 )
commandNumber = FDONOTHING;
/* look at the second character of the string */
switch( *++s ) {
case 't': n = 0; break; /* top left or right corner */
case 'b': n = 4; break; /* bottom left or right corner */
default: n = 8; break; /* right border */
}
++s; /* move to the third character in the string */
if( n == 8 ) { /* right border */
/* skip the third character */
if( *++s == 'r' ) /* right button */
n = 9;
} else { /* all 4 corners */
if( *s == 'r' ) /* top or bottom right corner */
n += 2;
if( *++s == 'm' ) /* middle button */
++n;
}
windowPoints[n] = (unsigned char)commandNumber;
}
void pascal
/* XTAG:setMQuadrant */
setMQuadrant(s, value)
unsigned char *s, *value;
{
extern int quad22, quad45, quad67;
int degrees;
degrees = atoi(value);
if( s[1] == '1' )
quad67 = degrees;
else if( s[1] == '2' )
quad45 = degrees;
else
quad22 = degrees;
}
void pascal
/* XTAG:copyStringToMenuSpace */
copyStringToMenuSpace(value)
unsigned char *value;
{
extern unsigned char far *menuSpace;
extern unsigned char *userMessages[];
extern int nextSpace;
while( 1 ) {
/* skip the initial " with the preincrement ++ */
menuSpace[nextSpace++] = *++value;
if( nextSpace >= MENUSPACE ) {
cprintf(userMessages[MENUSPMSG]);
break;
}
if( *value == '\0' ) {
--nextSpace;
/* eliminate the final " (if there is one) */
if( menuSpace[nextSpace-1] == '"' )
menuSpace[nextSpace-1] = '\0';
else
++nextSpace